package com.expressage.controller;


import com.expressage.po.State;
import com.expressage.service.StateService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 快递状态表控制器
 */
@Controller
public class StateController {

    Logger logger = Logger.getLogger(StateController.class);

    @Autowired
    StateService stateService;

    @RequestMapping("/statelist")
    public String findAll(Model model){
        logger.info("进入了快递状态列表");
        List<State> list = stateService.findAll();
        model.addAttribute("list",list);
        logger.info(list);
        return "jspafter/statelist";
    }

    @RequestMapping("/toaddstate")
    public String toadd(Model model){
        logger.info("======进入了toaddaction========");
        return "jspafter/addstate";
    }

    @RequestMapping("/addstate")
    public String addstate(State state){
        logger.info("进入了添加快递状态控制器");
        Boolean flag = stateService.insert(state);
        logger.info(flag?"添加员工成功":"添加员工失败");
        return "redirect:statelist.action";
    }

    @RequestMapping("/toupdatestate")
    public String toupdate(int stateid,Model model){
        logger.info("进入了去修改控制器");
        State state = stateService.findByStateid(stateid);
        logger.info(state);
        model.addAttribute("state",state);
        return "jspafter/updatestate";
    }

    @RequestMapping("/updatestate")
    public String update(State state){
        logger.info("进入了修改控制器");
        Boolean flag = stateService.update(state);
        logger.info(flag?true:false);
        return "redirect:statelist.action";
    }

    @RequestMapping("/deletestate")
    public String delete(int[] stateid){
        logger.info("进入了删除快递状态信息控制器");
        if(stateid.length>0){
            boolean falg = stateService.delete(stateid);
            logger.info(falg?true:false);
        }
        return "redirect:statelist.action";
    }

}
